// TypeScript file
class startView extends egret.DisplayObjectContainer {
    public constructor() {
        super();
        this.width = 750;
        this.height = 1334;
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.init, this);
    }

    private shp: egret.Shape;

    private init() {
        this.initButton("初始化", 20, 20, this.initshp);
        this.initButton("擦除", 200, 20, this.clear);
        this.initButton("画线", 20, 1000, this.lineTo);
        this.initButton("画矩形", 200, 1000, this.drawRect);
        this.initButton("画圆", 400, 1000, this.drawCircle);
        this.initButton("曲线", 20, 1100, this.curveTo);
        this.initButton("绘制圆弧", 200, 1100, this.drawArc);
        this.initButton("画弧", 400, 1100, this.drawArc1);
        this.initButton("画拱形", 20, 1200, this.drawArc2);
        this.initButton("画扇形", 200, 1200, this.drawArc3);
        this.initButton("圆角矩形", 400, 1200, this.drawRoundRect);
        this.initshp();
    }



    //测试
    private test() {
        console.log("测试")
    }

    //圆角矩形
    private drawRoundRect() {
        this.shp.graphics.beginFill(0x00ff00);
        this.shp.graphics.drawRoundRect(200, 500, 400, 200, 50, 50);
        this.shp.graphics.endFill();
    }


    //画扇形
    private drawArc3() {
        let r = 50;
        this.shp.graphics.beginFill(0xff0000);
        this.shp.graphics.moveTo(r, r);//绘制点移动(r, r)点
        this.shp.graphics.lineTo(r * 2, r);//画线到弧的起始点
        this.shp.graphics.drawArc(50, 50, 50, 0, 260 * Math.PI / 180, false);//从起始点顺时针画弧到终点
        this.shp.graphics.lineTo(r, r);//从终点画线到圆形。到此扇形的封闭区域形成
        this.shp.graphics.endFill();
    }

    //画拱形
    private drawArc2() {
        this.shp.graphics.beginFill(0xff0000);
        this.shp.graphics.drawArc(150, 250, 50, 0, Math.PI / 180 * 60, true);
        this.shp.graphics.endFill();
    }

    //画弧
    private drawArc1() {
        this.shp.graphics.lineStyle(5, 0xffff00);
        this.shp.graphics.drawArc(50, 50, 50, 0, Math.PI / 180 * 60, false);
        this.shp.graphics.drawArc(50, 50, 100, 0, Math.PI / 180 * 60, false);
        this.shp.graphics.drawArc(50, 50, 150, 0, Math.PI / 180 * 60, false);
        this.shp.graphics.drawArc(50, 50, 200, 0, Math.PI / 180 * 60, false);
        this.shp.graphics.endFill();
    }

    //绘制圆弧
    private drawArc() {
        this.shp.graphics.beginFill(0x1122cc);
        this.shp.graphics.drawArc(200, 200, 100, 0, Math.PI, true);
        this.shp.graphics.endFill();

        this.shp.graphics.beginFill(0x1122cc);
        this.shp.graphics.drawArc(400, 400, 100, 0, Math.PI / 2, false);
        this.shp.graphics.endFill();
    }


    //曲线
    private curveTo() {
        this.shp.graphics.lineStyle(2, 0x00ff00);
        this.shp.graphics.moveTo(50, 50);
        this.shp.graphics.curveTo(100, 100, 200, 50);
        this.shp.graphics.endFill();

        this.shp.graphics.lineStyle(2, 0x00ff00);
        this.shp.graphics.moveTo(150, 150);
        this.shp.graphics.cubicCurveTo(100, 100, 200, 50, 400, 400);
        this.shp.graphics.endFill();
    }


    //画圆
    private drawCircle() {
        this.shp.graphics.lineStyle(10, 0x00ff00);
        this.shp.graphics.beginFill(0xff0000, 1);
        this.shp.graphics.drawCircle(100, 100, 50);
        this.shp.graphics.endFill();

        this.shp.graphics.lineStyle(0, 0x00ff00);
        this.shp.graphics.beginFill(0xff0000, 1);
        this.shp.graphics.drawCircle(500, 100, 100);
        this.shp.graphics.endFill();
    }

    //画矩形
    private drawRect() {
        this.shp.graphics.lineStyle(10, 0x00ff00);
        this.shp.graphics.beginFill(0xff0000, 1);
        this.shp.graphics.drawRect(10, 100, 100, 200);
        this.shp.graphics.endFill();
        
        
    }

    //画线
    private lineTo() {
        this.shp.graphics.lineStyle(5, 0x00ff00);
        this.shp.graphics.moveTo(10, 10);
        this.shp.graphics.lineTo(600, 400);
    }

    //擦除
    private clear() {
        this.shp.graphics.clear();
    }

    //初始化
    private initshp() {
        if (this.shp) {
            this.removeChild(this.shp);
            this.shp = null;
        }
        this.shp = new egret.Shape();
        this.shp.y = 100;
        this.addChild(this.shp);
    }

    //通用按钮
    private initButton(textContent, x, y, callback) {
        var text: egret.TextField = new egret.TextField();
        text.text = textContent;
        text.textColor = 0x000000;
        text.background = true;
        text.backgroundColor = 0x03f425;
        text.x = x;
        text.y = y;
        text.touchEnabled = true;
        text.addEventListener(egret.TouchEvent.TOUCH_TAP, callback, this);
        this.addChild(text);
    }
}